-- CALC_CAVE_BONUS_1

-- 计算怪物巢穴副本奖励
-- @param user    玩家对象
-- @param args    奖励计算参数
-- @param grade   副本难度
-- @param layer   地牢层数
return function(user, args, grade, layer)
    -- caution：如果修改该公式，服务器请一并修改

    -- 获取地牢难度系数
    local dugeonId = DungeonM.getDungeonId();
    if dugeonId == nil then
        dugeonId = user.dbase:query("currentDungeon");
    end
    local layerFix = DungeonAreaM.query(dugeonId, "layer_fix");
    -- grade : 副本难度
    -- layer : 地牢层数
    local fixCo, attack, magic = 0, 0, 0;
    local randSeed = DungeonM.getRandSeed("DUNGEON_CAVE1");
    local arr = {};

    if grade == INSTANCE_GRADE_HARD then
        fixCo = 200;
        magic = 2;
        arr   = { { ["classId"] = 4005, ["amount"] = 1, ["ratio"] = 100, },                      -- 卷轴“大地之门”×1+floor/20
            { ["classId"] = 5115, ["amount"] = 1, ["ratio"] = 100, }, };                         -- 宝物“土元素之靴”×1
    elseif grade == INSTANCE_GRADE_DIFFICULT then
        fixCo = 150;
        magic = 1;
        arr   = { { ["classId"] = 4004, ["amount"] = 1 + math.modf(layer / 30), ["ratio"] = 100, },    -- 卷轴“超重力”×1+floor/30
            { ["classId"] = 5114, ["amount"] = 1, ["ratio"] = 100, }, };                         -- 宝物“重力之源”×1
    elseif grade == INSTANCE_GRADE_NORMAL then
        fixCo = 100;
        arr   = { { ["classId"] = 4003, ["amount"] = 1 + math.modf(layer / 30), ["ratio"] = 100, },    -- 卷轴“地刺术”×1+floor/30
            { ["classId"] = 5113, ["amount"] = 1, ["ratio"] = 100, }, };                         -- 宝物“荆棘之球”×1
    else
        fixCo = 50;
        arr   = { { ["classId"] = 4001, ["amount"] = 1 + math.modf(layer / 20), ["ratio"] = 100, },    -- 卷轴“石肤术”×1+floor/20
            { ["classId"] = 4002, ["amount"] = 1 + math.modf(layer / 30), ["ratio"] = 100, },    -- 卷轴“地震术”×1+floor/30
            { ["classId"] = 5111, ["amount"] = 1, ["ratio"] = 100, },                            -- 宝物“花岗岩手套”×1
            { ["classId"] = 5112, ["amount"] = 1, ["ratio"] = 100, }, };                         -- 宝物“黑曜石铠甲”×1
    end

    local ret = {};
    local bonus;

    if fixCo > 0 then
        -- 探索点奖励
        table.insert(ret, { 2, "search_point", FormulaM.invoke("CALC_SEARCH_POINT_COST", fixCo, layer, layerFix), });
    end

    if attack > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "attack", attack, });
    end

    if magic > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "magic", magic, });
    end

    if #arr > 0 then
        -- 物品奖励
        bonus = fetchElemBySeed(arr, randSeed);
        table.insert(ret, { 1, bonus["classId"], bonus["amount"], });
    end

    return ret;
end